﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;
using System.Windows;
using System.Windows.Controls;

namespace SharePointCommander.Model.TreeView
{
    public class SCJobDefinitionCollection : SCTreeViewItem<SPJobDefinitionCollection>
    {
        public SCJobDefinitionCollection(SCTreeViewItem parent, SPJobDefinitionCollection jobDefinitions)
            : base(parent, jobDefinitions)
        {
            Header = "Job Definitions";
            Expanded += new RoutedEventHandler(SCJobDefinitionCollection_Expanded);
            ItemsSource = new object[] { null };
        }

        void SCJobDefinitionCollection_Expanded(object sender, System.Windows.RoutedEventArgs e)
        {
            TreeViewItem item = e.Source as TreeViewItem;
            if (!item.ItemsSource.OfType<SCJobDefinition>().Any())
            {
                item.ItemsSource = from jd in SPObject select new SCJobDefinition(this, jd);
            }
        }
    }
}
